//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "StudentDistribution.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (Int32 n) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phStudentDistribution = NULL;
#endif
        QuantLib::Integer _n = (QuantLib::Integer)ValueHelper::Convert (n);
        _ppStudentDistribution = new boost::shared_ptr<QuantLib::StudentDistribution> (new QuantLib::StudentDistribution ( _n ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (boost::shared_ptr<QuantLib::StudentDistribution>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStudentDistribution = NULL;
#endif
	_ppStudentDistribution = &childNative;
    
}
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (QuantLib::StudentDistribution& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phStudentDistribution = NULL;
#endif
	_ppStudentDistribution = new boost::shared_ptr<QuantLib::StudentDistribution> (&childNative);
    
    _StudentDistributionOwner = owner;
    
}

Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (CStudentDistribution^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStudentDistribution = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppStudentDistribution = new boost::shared_ptr<QuantLib::StudentDistribution> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStudentDistribution = NULL;
#endif
	if (!t->IsSubclassOf(CStudentDistribution::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (QuantLib::Handle<QuantLib::StudentDistribution>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phStudentDistribution = &childNative;
	_ppStudentDistribution = &static_cast<boost::shared_ptr<QuantLib::StudentDistribution>>(childNative.currentLink());
    
    _StudentDistributionOwner = owner;
}
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (QuantLib::Handle<QuantLib::StudentDistribution> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phStudentDistribution = &childNative;
	_ppStudentDistribution = &static_cast<boost::shared_ptr<QuantLib::StudentDistribution>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CStudentDistribution::CStudentDistribution (QuantLib::StudentDistribution childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phStudentDistribution = NULL;
#endif
	_ppStudentDistribution = new boost::shared_ptr<QuantLib::StudentDistribution> (new QuantLib::StudentDistribution (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CStudentDistribution::~CStudentDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppStudentDistribution != NULL)
    {
	    delete _ppStudentDistribution;
        _ppStudentDistribution = NULL;
    }
}
Cephei::QL::Math::Distributions::CStudentDistribution::!CStudentDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppStudentDistribution != NULL)
    {
	    delete _ppStudentDistribution;
    }
}
QuantLib::StudentDistribution& Cephei::QL::Math::Distributions::CStudentDistribution::GetReference ()
{
    if (_ppStudentDistribution == NULL) throw gcnew NativeNullException ();
	return **_ppStudentDistribution;
}
boost::shared_ptr<QuantLib::StudentDistribution>& Cephei::QL::Math::Distributions::CStudentDistribution::GetShared ()
{
    if (_ppStudentDistribution == NULL) throw gcnew NativeNullException ();
	return *_ppStudentDistribution;
}
QuantLib::StudentDistribution* Cephei::QL::Math::Distributions::CStudentDistribution::GetPointer ()
{
    if (_ppStudentDistribution == NULL) throw gcnew NativeNullException ();
	return &**_ppStudentDistribution;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::StudentDistribution>& Cephei::QL::Math::Distributions::CStudentDistribution::GetHandle ()
{
	if (_phStudentDistribution == NULL)
	{
		_phStudentDistribution = new Handle<QuantLib::StudentDistribution> (*_ppStudentDistribution);
	}
	return *_phStudentDistribution;
}
#endif
bool Cephei::QL::Math::Distributions::CStudentDistribution::HasNative () 
{
	return (_ppStudentDistribution != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::IStudentDistribution^ Cephei::QL::Math::Distributions::CStudentDistribution_Factory::Create (Int32 n)
{
    return gcnew CStudentDistribution ( n);
}
